<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>任务管理</title>
    <style>
        body {
            font-family: "Arial", sans-serif;
            margin: 0;
            padding: 0;
            background: linear-gradient(to right, #aed581, #81c784);
            color: #333;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
        }

        .container {
            width: 90%;
            max-width: 1200px;
            margin: 20px 0;
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 20px;
        }

        .header h1 {
            margin: 0;
            color: #388e3c;
        }

        .toolbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .search-bar {
            display: flex;
            gap: 10px;
            flex-grow: 1;
        }

        .search-bar input {
            flex-grow: 1;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        .search-bar button {
            background: #388e3c;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .search-bar button:hover {
            background: #66bb6a;
        }

        .add-task {
            background: #81c784;
            color: white;
            text-decoration: none;
            padding: 10px 20px;
            border-radius: 5px;
            transition: background 0.3s;
        }

        .add-task:hover {
            background: #66bb6a;
        }

        .task-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
        }

        .task-card {
            background: #f9f9f9;
            border-radius: 10px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            padding: 20px;
            text-align: left;
        }

        .task-card h3 {
            margin: 0 0 10px;
            color: #388e3c;
        }

        .task-card p {
            margin: 5px 0;
            color: #555;
        }

        .task-card .actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
            margin-top: 15px;
        }

        .task-card .actions a {
            text-decoration: none;
            padding: 5px 10px;
            border-radius: 5px;
            background: #e8f5e9;
            color: #388e3c;
            transition: background 0.3s;
        }

        .task-card .actions a:hover {
            background: #c8e6c9;
        }

        .pagination {
            display: flex;
            justify-content: center;
            margin-top: 20px;
            gap: 10px;
        }

        .pagination a {
            padding: 5px 15px;
            text-decoration: none;
            border-radius: 5px;
            background: #f1f1f1;
            color: #333;
            transition: background 0.3s;
        }

        .pagination a.active {
            font-weight: bold;
            background: #388e3c;
            color: white;
        }

        .pagination a:hover {
            background: #e0e0e0;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1>任务管理</h1>
    </div>
    <div class="toolbar">
        <form method="get" action="TaskServlet" class="search-bar">
            <input type="text" name="search" placeholder="搜索任务" value="${param.search}" />
            <button type="submit">搜索</button>
        </form>
        <a href="addtask.jsp" class="add-task">新增任务</a>
        <a href="admin.jsp" class="add-task">返回</a>
    </div>
    <div class="task-list">
        <c:forEach var="task" items="${tasks}">
            <div class="task-card">
                <h3>任务 ID: ${task.id}</h3>
                <p><strong>订单 ID:</strong> ${task.ordersid}</p>
                <p><strong>菜品名称:</strong> ${task.menuname}</p>
                <p><strong>数量:</strong> ${task.quantity}</p>
                <p><strong>状态:</strong>
                    <c:choose>
                        <c:when test="${task.status == 1}">待做</c:when>
                        <c:when test="${task.status == 2}">已做</c:when>
                    </c:choose>
                </p>
                <p><strong>创建时间:</strong> ${task.cretime}</p>
                <div class="actions">
                    <a href="edittask.jsp?id=${task.id}">编辑</a>
                    <a href="TaskServlet?action=delete&id=${task.id}"
                       onclick="return confirm('确认删除吗？');">删除</a>
                </div>
            </div>
        </c:forEach>
    </div>
    <div class="pagination">
        <c:forEach var="page" begin="1" end="${totalPages}">
            <a href="TaskServlet?page=${page}&search=${param.search}"
               class="${page == currentPage ? 'active' : ''}">${page}</a>
        </c:forEach>
    </div>
</div>
</body>
</html>
